package com.ifyyf.controller;

import com.ifyyf.pojo.Dept;
import com.ifyyf.service.DeptClintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author if
 * @Description: 消费者客户端
 * 用户应该访问的是本接口ip:80/consumer/dept/getAll
 * 然后代理到了Feign负载均衡接口类，由Feign的接口类根据算法(轮询)打向配置好了的并注册到了注册中心的服务接口去
 * 打向的主机地址由@FeignClient(value = "SPRINGCLOUD-PROVIDER-DEPT")注解接管
 * 具体的接口地址由方法上的@GetMapping("/dept/getAll")接管
 * 总结：用户=>客户端Controller=>Feign负载均衡=>注册中心集群=>服务端Controller=>mysql数据库集群
 * @Date 2021-08-24 下午 01:03
 */
@RestController
@CrossOrigin
@RequestMapping("/consumer/dept")
public class DeptConsumerController {

    @Autowired
    private DeptClintService deptClintService=null;
    /**
     * RestFul风格
     * @param deptno
     * @return
     */
    @GetMapping("/get/{deptno}")
    public Dept get(@PathVariable("deptno") Long deptno){
        return deptClintService.queryById(deptno);
    }

    /**
     * list返回值就给List.class
     * @return
     */
    @GetMapping("/getAll")
    public List<Dept> getAll(){
        return deptClintService.queryAll();
    }
}
